package practise.alogrithm.hundredInterviewQuestions.secondTime;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Richard on 7/26/2014.
 */
public class DevideArrayFrontOddEndEven {
    public void devide(List<Integer> array){

        for(int front = 0,end=array.size()-1;front<end;){
            if(array.get(front)%2==1){
                front++;
            }
            else {
                swap(array,front,end--);
            }
            if(array.get(end)%2==0){
                end--;
            }else {
                swap(array,front++,end);
            }
        }
        System.out.print(array);
    }

    private void swap(List<Integer> array, int index1, int index2){
        Integer temp = array.get(index1);
        array.set(index1,array.get(index2));
        array.set(index2,temp);
    }

    public static void main(String[] args){
        new DevideArrayFrontOddEndEven().devide(new ArrayList<Integer>(Arrays.asList(new Integer[]{1,2,3,4,5,6,7,8,9,0})));
    }
}
